﻿@using HCQ2_Model
@using HCQ2_Common
@{
    ViewBag.Title = "奇点元宇宙编辑审核";
}
@section headerSection{
    <link href="~/Resources/mainFrame/js/plugins/zTree3/css/metroStyle/metroStyle.css" rel="stylesheet" />
    <script src="~/Resources/mainFrame/js/plugins/zTree3/js/jquery.ztree.core.min.js"></script>
    <script src="~/Resources/mainFrame/js/plugins/zTree3/js/jquery.ztree.excheck.min.js"></script>
    <script src="~/Resources/mainFrame/js/plugins/zTree3/js/jquery.ztree.exedit.min.js"></script>
    <script src="~/Resources/tools/search_zTree.js"></script>
    <style>
        #unitTree {
            width: 400px;
            height: 300px;
            padding: 0;
            border: 1px solid #E7EAEC;
            background-color: #FFFFFF;
            position: fixed;
            z-index: 9;
            overflow: auto;
            display: none;
        }
    </style>
}
<div id="entryHtml" class="wrapper animated fadeInRight autoHeight">
    <!-- Panel Other -->
    <div class="row autoHeight" style="background-color: #fff;">
        <div class="col-sm-12 col-sm-leftRight">
            <form class="form-horizontal m-t" id="orgFormTable" method="post" style="margin-bottom:120px;">
                <div class="form-group">
                    <label class="col-sm-3 control-label">名称<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <input id="file_name" name="file_name" type="text" required="" aria-required="true" class="form-control input-sm" placeholder="请输入名称" />
                        <input id="file_id" name="file_id" type="hidden" />
                    </div>
                    <label class="col-sm-2 control-label">浏览次数<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <input id="browse_num" name="browse_num" type="text" class="form-control input-sm" value="0" required="" aria-required="true" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">简介：</label>
                    <div class="col-sm-3">
                        <textarea class="form-control" id="file_note" name="file_note" rows="2" placeholder="请输入简介"></textarea>
                    </div>
                    <label class="col-sm-2 control-label">点赞次数<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <input id="vr_star" name="vr_star" type="text" class="form-control input-sm" value="0" required="" aria-required="true" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">最大人数<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <input id="pag_num" name="pag_num" type="text" required="" aria-required="true" class="form-control input-sm" placeholder="请输入最大人数" />
                    </div>
                    <label class="col-sm-2 control-label">购买次数<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <input id="pay_num" name="pay_num" type="text" class="form-control input-sm" value="0" required="" aria-required="true" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">最大时长<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3" style="display:flex;">
                        <input id="finishSpan" name="finishSpan" type="text" style="width: calc(100% - 40px);" required="" aria-required="true" class="form-control input-sm" placeholder="请输入最大时长" /><span style="line-height:30px;margin-left:5px;">小时</span>
                        <input id="finish_time" name="finish_time" type="hidden" />
                    </div>
                    <label class="col-sm-2 control-label">下载次数<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <input id="down_number" name="down_number" type="text" class="form-control input-sm" value="0" required="" aria-required="true" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">推荐<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <select id="isRecommend" name="isRecommend" data-live-search="true" class="form-control input-sm selectpicker" placeholder="@LangHelper.GetValue("GeneralJson.pleaseSelect")@LangHelper.GetValue("VRGoodManager.VRCloudWork.selectRecommended")" required="" aria-required="true">
                            <option value="0" selected>@LangHelper.GetValue("VRGoodManager.VRCloudWork.notRecommended")</option>
                            <option value="1">@LangHelper.GetValue("VRGoodManager.VRCloudWork.recommended")</option>
                        </select>
                        <input type="hidden" id="is_recommend" name="is_recommend" />
                    </div>
                    <label class="col-sm-2 control-label">审核通过时间：</label>
                    <div class="col-sm-3">
                        <input id="approve_time" name="approve_time" disabled="disabled" type="text" class="form-control input-sm" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">目录导航<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <input id="folder_name" name="folder_name" type="text" required="" aria-required="true" class="form-control input-sm" placeholder="@LangHelper.GetValue("GeneralJson.pleaseSelect")@LangHelper.GetValue("VRGoodManager.VRCloudWork.scope")" />
                        <div id="unitTree" class="col-sm-3"></div>
                        <input id="folder_id" name="folder_id" type="hidden" />
                        <input id="folder_path" name="folder_path" type="hidden" />
                    </div>
                    <label class="col-sm-2 control-label">审核人：</label>
                    <div class="col-sm-3">
                        <input id="approve_name" name="approve_name" disabled="disabled" type="text" class="form-control input-sm" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">代码<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <input id="file_code" name="file_code" type="text" class="form-control input-sm" placeholder="请输入代码" />
                        <input id="folder_num" name="folder_num" type="hidden" class="form-control input-sm" />
                    </div>
                    <label class="col-sm-2 control-label">最后修改时间：</label>
                    <div class="col-sm-3">
                        <input id="update_time" name="update_time" disabled="disabled" type="text" class="form-control input-sm" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">序号：</label>
                    <div class="col-sm-3">
                        <input id="file_order" name="file_order" onblur="help.int('file_order')" type="text" class="form-control input-sm" placeholder="请输入序号" />
                    </div>
                    <label class="col-sm-2 control-label">最后修改人：</label>
                    <div class="col-sm-3">
                        <input id="update_name" name="update_name" disabled="disabled" type="text" class="form-control input-sm" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">应用ID<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <input id="attach_url" name="attach_url" type="text" required="" aria-required="true" class="form-control input-sm" placeholder="请输入应用" />
                    </div>
                    <label class="col-sm-2 control-label">创建时间：</label>
                    <div class="col-sm-3">
                        <input id="create_time" name="create_time" disabled="disabled" type="text" class="form-control input-sm" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">应用大小<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3" style="display:flex;">
                        <input id="file_size" name="file_size" type="text" style="width: calc(100% - 40px);" onblur="help.int('file_order')" required="" aria-required="true" class="form-control input-sm" placeholder="请输入应用大小" /><span style="line-height:30px;margin-left:5px;">KB</span>
                    </div>
                    <label class="col-sm-2 control-label">创建人：</label>
                    <div class="col-sm-3">
                        <input id="create_name" name="create_name" disabled="disabled" type="text" class="form-control input-sm" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">状态<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <select id="file_status" name="file_status" data-live-search="true" disabled="disabled" class="form-control input-sm selectpicker" placeholder="请选择状态" required="" aria-required="true">
                            <option value="5" selected>上架</option>
                            <option value="6">审核不通过</option>
                        </select>
                    </div>
                    <label class="col-sm-2 control-label">最低价格：</label>
                    <div class="col-sm-3">
                        <input id="file_money" name="file_money" disabled="disabled" type="text" class="form-control input-sm" />
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                @{
                    List<T_VRGoodDisiPrice> priceList = (List<T_VRGoodDisiPrice>)ViewBag.goodPrice;
                    int goodStatus = ViewBag.goodStatus;
                    if (priceList.Count > 0)
                    {
                        for (int i = 0; i < priceList.Count; i += 2)
                        {
                            int j = i;
                            string ptitle = priceList[j].op_month > 0 ? priceList[j].op_month + "个月价格" : "无限期价格";
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">@ptitle：</label>
                                    <div class="col-sm-3">
                                        <input id="file_price" name="file_price" type="text" op_month="@priceList[j].op_month" class="form-control input-sm filePrice" placeholder="@priceList[j].op_month@LangHelper.GetValue("VRGoodManager.VRCommon.monthMoney")" value="@priceList[j].ori_price" />
                                    </div>
                                    @{
                                        if ((priceList.Count - j) > 1)
                                        {
                                            j++;
                                            ptitle = priceList[j].op_month > 0 ? priceList[j].op_month + "个月价格" : "无限期价格";
                                            if (priceList.Count > j)
                                            {
                                                <label class="col-sm-2 control-label">@ptitle：</label>
                                                <div class="col-sm-3">
                                                    <input id="file_price" name="file_price" type="text" op_month="@priceList[j].op_month" class="form-control input-sm filePrice" placeholder="@priceList[j].op_month@LangHelper.GetValue("VRGoodManager.VRCommon.monthMoney")" value="@priceList[j].ori_price" />
                                                </div>
                                            }
                                        }
                                    }
                                </div>
                        }
                    }
                    else if (goodStatus != 0)
                    {
                        <div class="form-group">
                            <label class="col-sm-3 control-label">1个月价格：</label>
                            <div class="col-sm-3">
                                <input id="file_price" name="file_price" type="text" op_month="1" class="form-control input-sm filePrice" placeholder="请输入1个月价格" />
                            </div>
                            <label class="col-sm-2 control-label">6个月价格：</label>
                            <div class="col-sm-3">
                                <input id="file_price" name="file_price" type="text" op_month="6" class="form-control input-sm filePrice" placeholder="请输入6个月价格" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">12个月价格：</label>
                            <div class="col-sm-3">
                                <input id="file_price" name="file_price" type="text" op_month="12" class="form-control input-sm filePrice" placeholder="请输入12个月价格" />
                            </div>
                            <label class="col-sm-2 control-label">无限期价格：</label>
                            <div class="col-sm-3">
                                <input id="file_price" name="file_price" type="text" op_month="0" class="form-control input-sm filePrice" placeholder="请输入无限期价格" />
                            </div>
                        </div>
                    }
                }
                <div id="approveNote" class="form-group" style="display:none;">
                    <label class="col-sm-3 control-label">审核意见：</label>
                    <div class="col-sm-8">
                        <textarea class="form-control" id="approve_note" name="approve_note" rows="2" placeholder="请输入审核意见!"></textarea>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
@section footSection{
    <script>
        var fileId, isread, isFolder = false, doc_type, pageType, pro_type;
        var entryType = $.getUrls("entryType"), $file_status,
            folder_id, folder_name, folder_path, isApprove;//是否为审核
        var unitzTree, isHeader = false;//是否为头记课件
        var entryManager = {
            initPage: function () {
                showLoadBoxs();
                if (!entryManager.initData())
                    return false;                
                entryManager.bindZtree();
                //entryManager.initSelect();
                entryManager.initForm();
                entryManager.bindEvent();
                delLoadBoxs();
            },
            initData: function () {
                var guid = $.getGuid().replaceAll("-", "");
                $('#file_code').val(guid);
                $('#folder_num').val(guid);
                fileId = $.getUrls("file_id");
                doc_type = $.getUrls("doc_type");
                pageType = $.getUrls("pageType");
                folder_id = $.getUrls("folder_id");
                folder_name = $.getUrls("folder_name");
                folder_path = $.getUrls("folder_path");
                isread = $.getUrls("read"); 
                pro_type = $.getUrls("pro_type");
                isApprove = $.getUrls("isApprove");
                if (!pageType)
                    pageType = "";
                if (folder_name)
                    folder_name = decodeURI(folder_name);
                //待审核时去掉所属项目
                if (doc_type === 5)
                    pageType = "";
                if (folder_id) {
                    $('#folder_name').val(folder_name);
                    $('#folder_id').val(folder_id);
                    $('#folder_path').val(folder_path);
                }
                //审核
                if (isApprove === "approve") {
                    $('#approveNote').css("display", "block");
                    $('#file_status').removeAttr("disabled");
                }
                return true;
            },
            //无需要的下拉
            initSelect: function () {
                //产品类别
                $('#pro_type').initSelectcontrol("vrProType",false,"5");
                //作品格式
                $('#pro_form').initSelectcontrol("vrProForm");
                $('#file_classify').initSelectcontrol("docClassify",true);
                $('#folder_limit').initSelectcontrol("docLimits");
                $.ajax({
                    url: ctx + '/SysCommon/GetDictionaryByCode',
                    type: "post",
                    cache: false,
                    async: false,
                    data: { fieldCode: 'SysUserUnit' },
                    dataType: 'json',
                    success: function (data) {
                        if (data.Statu === 1) {
                            layer.msg(data.Msg, { icon: 5 });
                            return false;
                        }
                        var itemStr = "";
                        $.each(data.Data, function (i, item) {
                            itemStr += "<option value='" + item.code_value + "'>" + item.code_name + "</option>";
                        });
                        $('#unit_code').append(itemStr);
                        $('.selectpicker').selectpicker({ size: 6 });
                        $('.selectpicker').selectpicker('refresh');
                    },
                    error: function () {
                        layer.msg(Lang.GeneralJson.dataException, { icon: 5 });
                    }
                });
            },
            initForm: function () {
                $('#orgFormTable').resetHideValidForm();
                if (!fileId)
                    return false;
                $.ajax({
                    type: 'post',
                    url: ctx + '/VRQDMeta/GetProgramData/' + fileId,
                    dataType: 'json',
                    async: false,
                    success: function (data) {
                        if (data.Statu === 0) {
                            var result = data.Data;
                            //默认上架
                            result.file_status = 5;
                            $('#orgFormTable')[0].reset();//重置表单
                            $('#orgFormTable').LoadForm(result);//表单填充数据
                            //$('#folder_name').val(folder.folder_name);
                            //$('#folder_id').val(folder.folder_id);
                            //$('#folder_path').val(folder.folder_path);
                            //判断是否只读
                            if (isread) {
                                //只读
                                $('#orgFormTable').find("input,textarea").attr("disabled", true);
                                $('#orgFormTable').find("select").next("div").children("button").attr("disabled", true);
                            }
                            $('button.disabled ').css("background-color", "#EEEEEE");
                        }
                        else
                            layer.msg(data.Msg, { icon: 5 });
                    }
                });
            },
            saveForm: function (indexForm) {
                if ($('#orgFormTable').valid()) {
                    var filePrice = $('.filePrice'), listPrice = [];
                    $.each(filePrice, function (index,item) {
                        listPrice.push({
                            op_month: $(item).attr("op_month"),
                            file_price: $(item).val()
                        });
                    });
                    var $data = {
                        isApprove: isApprove,
                        listPrice: listPrice,
                        entryType: entryType,
                        price: $('#file_price').val()
                    };
                    //最大时长
                    var t = $('#finishSpan').val();
                    if (t) 
                        $('#finish_time').val(parseFloat(t) * 60 * 60);
                    //推荐
                    var isRecommend = $('#isRecommend').val();
                    if (isRecommend === "1")
                        $('#is_recommend').val(true);
                    else
                        $('#is_recommend').val(false);
                    //验证通过
                    if (!$('#file_code').val()) {
                        layer.alert(Lang.GeneralJson.mustInputMessage);
                        return false;
                    }
                    $('#orgFormTable').ajaxSubmit({
                        url: ctx + '/VRQDMeta/EditProgram',
                        type: "post",
                        data: $data,
                        dataType: "json",
                        beforeSubmit: function (arr, $form, options) {
                            layer.msg(Lang.GeneralJson.submitData, { icon: 1, time: 5000 });
                        },
                        success: function (result, status, xhr, $form) {
                            if (result.Statu === 0) {
                                layer.msg(Lang.GeneralJson.saveAccess, { icon: 6 });
                                window.parent.docManager.closeIndexForm(indexForm);
                                return true;
                            }
                            else {
                                layer.alert(result.Msg, { icon: 5 });
                                return false;
                            }
                        },
                        error: function (xhr, status, error, $form) {
                            layer.msg(Lang.GeneralJson.saveError, { icon: 5 });
                        }
                    });
                } else {
                    layer.msg(Lang.GeneralJson.mustInputMessage, { icon: 5 });
                    return false;
                }
            },
            //绑定事件
            bindEvent:function(){
                $('#folder_name').on('click', function (event) {
                    if (!isFolder) {
                        //打开
                        $('#unitTree').slideDown();
                        isFolder = true;
                    } else {
                        //关闭
                        $('#unitTree').slideUp();
                        isFolder = false;
                    }
                    event.stopPropagation();
                });
                $('#entryHtml').on('click', function () {
                    //if (isFolder) {
                    //    $('#unitTree').slideUp();
                    //    isFolder = false;
                    //}
                });
            },
            //素材、作品树
            //2.2采用Ztree初始化文档树
            bindZtree: function () {
                var setting = {
                    view: {
                        showIcon: true,
                        selectedMulti: false,
                        fontCss: getFontCss
                    },
                    edit: {
                        enable: true,
                        showRemoveBtn: false,
                        showRenameBtn: false
                    },
                    async: {
                        enable: true,
                        dataType: "text",
                        type: "post",
                        url: ctx + "/DocManager/GetDocTreeData?pro_type=" + pro_type + "&doc_type=" + doc_type + "&isNum=1&pageType=QDMeta",
                        autoParam: ["id"]
                    },
                    data: {
                        key: { title: "name", name: "name" },
                        simpleData: { enable: true, idKey: "id", pIdKey: "pId", rootPId: 0 }
                    },
                    check: {
                        enable: false,
                        autoCheckTrigger: true,
                        chkStyle: "checkbox",
                        chkboxType: { "Y": "p", "N": "ps" }
                    },
                    callback: {
                        onAsyncError: function () {
                            layer.msg(Lang.GeneralJson.initUnitError, { icon: 5 });
                        },
                        onAsyncSuccess: function (event, treeId, treeNode, msg) {
                        },
                        onClick: function (event, treeId, treeNode) {
                            $('#unitTree a').css("color", "#333");
                            $('#' + treeNode.tId + '_a').css("color", "#ffffff");
                            $('#folder_id').val(treeNode.id);
                            $('#folder_path').val(treeNode.folder_path);
                            $('#unitTree').slideUp();
                            var folderName = treeNode.name;
                            if (folderName.indexOf('(') > -1)
                                $('#folder_name').val(folderName.substring(0, folderName.indexOf('(')));
                            else
                                $('#folder_name').val(folderName);
                            isFolder = false;
                        }
                    }
                };
                unitzTree = $("#unitTree").initzTreeView(setting, 'ushow');
            }
        }
        $(function(){
            //初始化Page
            entryManager.initPage();
        });
    </script>
}